package thinkingJava.chapter18;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class BufferedInputFile {
	public static String read(String filename) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(filename));
		String s;
		StringBuffer sb = new StringBuffer();
		while ((s = br.readLine()) != null) {
			sb.append(s).append("\n");
		}
		br.close();
		return sb.toString();
	}
	public static void main(String[] args) throws IOException {
//		System.out.println(BufferedInputFile.class.getClassLoader().getResource(""));
		System.out.println(new File("").getAbsolutePath());
//		System.out.println(Thread.currentThread().getContextClassLoader().getResource("").getPath());
		System.out.println(read("D:\\CVSROOT\\JavaSE\\src\\thinkingJava\\chapter18\\BufferedInputFile.java"));
		System.out.println("------------------------------------------------------------------");
		System.out.println(read(BufferedInputFile.class.getClassLoader().getResource(BufferedInputFile.class.getName().replace(".", "/") + ".class").getFile()));
	}
}
